{extend name='public/base' /}

{block name="content"}
<style type="text/css">
    .layui-form-pane .layui-form-label {
        overflow: initial !important;
    }
</style>
<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">
                    <div class="layui-inline">
                        <label class="layui-form-label">商户：</label>
                        <div class="layui-input-inline">
                            <select name="merchant_id" lay-verify="required" lay-search="">
                                <option value="0" ></option>
                                {volist name="merchant_list" id="t"}
                                {if empty($t.name)||$t.name=='-'}
                                <option value="{$t.id}" >{$t.company} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {else/}
                                <option value="{$t.id}" >{$t.name} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {/if}
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">员工：</label>
                        <div class="layui-input-inline">
                            <input name="name" class="layui-input" id="name" value="" type="text"
                                   placeholder="请输入员工名称">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">员工状态：</label>
                        <div class="layui-input-inline">
                            <select name="status">
                                <option value="">请选择</option>
                                <option value="1">通过</option>
<!--                                <option value="2">离职申请</option>-->
                                <option value="3">已离职</option>
                                <option value="4">拒绝</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn layui-btn-sm" data-id="table_id" lay-filter="search"
                                lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button type="reset" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i
                                class="layui-icon layui-icon-refresh"></i>{:__('Reset')}
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>


    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>

</div>
{/block}

{block name="js"} <!--js处理区-->
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button type="button" lay-event="reload" class="layui-btn  layui-btn-sm  layui-btn-primary">刷新表格</button>
    </div>
</script>
<script type="text/html" id="operationTpl">

    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('MerchantEmployees/refundDetail')}" data-title="详情 " lay-event="refund">详情</a>

    {{# if(d.status==1){ }}
    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('MerchantEmployees/apply')}" data-title="离职"
       lay-event="apply">离职</a>
    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('MerchantEmployees/updatePassword')}" data-title="修改密码" lay-event="update"><i class="layui-icon">&#xe614;</i></a>
    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs {:node('MerchantEmployees/resetPassword')}" data-title="重置密码" lay-event="resetPassword"><i class="layui-icon ">&#x1007;</i></a>
    <!--    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('Release/refund')}" data-title="退费"-->
    <!--       lay-event="refund">退费</a>-->
    {{# } }}
    {{# if(d.status==2){ }}
    <!--    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('Release/apply')}" style="color: #e3e3e3">离职申请</a>-->
    <!--    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('Release/refund')}" data-title="退费" lay-event="refund">退费</a>-->
    {{# } }}
    {{# if(d.status==0){ }}
    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs {:node('MerchantEmployees/audit')}" data-title="通过" lay-event="audit"><i class="layui-icon ">通过</i></a>
    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs {:node('MerchantEmployees/noaudit')}" data-title="拒绝" lay-event="noaudit"><i class="layui-icon ">拒绝</i></a>
    <!--    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('Release/apply')}" style="color: #e3e3e3">离职申请</a>-->
    <!--    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('Release/refund')}" style="color: #e3e3e3">退费</a>-->
    {{# } }}
    {{# if(d.status==-1){ }}
    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('MerchantEmployees/apply')}" data-title="离职"
       lay-event="apply">离职</a>
<!--    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('Release/apply')}" style="color: #e3e3e3">已离职</a>-->
    <!--    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('Release/refund')}" style="color: #e3e3e3">退费</a>-->
    {{# } }}

</script>
<script>
    layui.use(['element', 'table', 'form', 'jquery', 'lucky', 'opTable'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky = layui.lucky;
        var opTable = layui.opTable;
        form.render();
        var myTables = table.render({
            elem: '#table_id',
            url: "{:url('index')}",
            defaultToolbar: ['filter', 'exports', 'print'],
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            even: true, //开启隔行背景
            id: 'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip', 'last'] //自定义分页布局
                , groups: 5 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
                , limit: 20
                , limits: [10, 20, 30, 50]
            },
            // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {title: '', type: 'checkbox', fixed: true},
                {title: 'id', field: 'id'},
                {title: '姓名', field: 'name'},
                {title: '手机号', field: 'mobile'},
                {
                    title: '所属商户', field: 'merchant_name', templet: function (item) {
                        return item.merchant.name;
                    }
                },
                {
                    field: 'create_time', title: '入职时间', templet: function (item) {
                        return layui.util.toDateString((item.create_time) * 1000)
                    }
                },
                {
                    field: 'status', title: '员工状态', templet: function (item) {
                        if (item.status == 1) {
                            return '通过';
                        } else if (item.status == 2) {
                            return '离职中'
                        } else if (item.status == 3) {
                            return '已离职'
                        } else if (item.status == -1) {
                            return '已离职'
                        }else if (item.status == 0) {
                            return '待审核'
                        }else if (item.status == 4) {
                            return '拒绝'
                        }   else {
                            return '未知';
                        }
                    }
                },
                {
                    field: 'is_type', title: '身份', templet: function (item) {
                        if (item.is_type == 1) {
                            return '店长';
                        } else if (item.is_type == 2) {
                            return '员工'
                        }else {
                            return '店长'
                        }
                    }
                },
                {templet: '#operationTpl', align: 'center', title: '操作',width:230}
            ]],
            //  展开的列配置
            openCols: [
                {field: 'desc', title: '描述信息'}
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id = parseInt(data.id);
            var layEvent = obj.event;
            if (layEvent === "apply") {
                lucky.FormatData(_id, "{:url('apply')}", "确认为该员工办离职申请？");
            } else if (layEvent === "refund") {
                var urls = "{:url('refundDetail')}?id=" + _id;
                lucky.CreateOpenForm("详情", urls);
            } else if (layEvent === 'update') {
                var urls = "{:url('updatePassword')}?id=" + _id;
                lucky.CreateOpenForm("修改登录密码", urls);
            } else if (layEvent === 'resetPassword') {
                var urls = "{:url('Common/resetPassword')}?id=" + _id + "&type=2";
                lucky.FormatData(_id, urls, '确认重置密码 ？');
            } else if (layEvent === "audit") {
                lucky.FormatData(_id, "{:url('audit')}",'确认审核通过?');
            }else if(layEvent =='noaudit'){
                lucky.FormatData(_id, "{:url('noaudit')}",'确认拒绝?');
            }
        });


        table.on('toolbar(table_id)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if (obj.event === "add") {
                lucky.CreateOpenForm("添加 ", "{:url('add')}");
                return false;
            } else if (obj.event === "close") {
                opTables.closeAll();
            } else if (obj.event === "open") {
                opTables.openAll();
            } else if (obj.event === "reload") {
                lucky.CreateReload();
            } else if (obj.event === "del") {
                var num = 0;
                var id = [];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num < 1) {
                    layer.msg("请选择一项", {time: 1500});
                    return false;
                }
                lucky.FormatData(id, "{:url('del')}");
                return false;
            }
        });

        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script>

{/block}
